 document.onkeydown = function(event) {
            var target, code, tag;
            if (!event) {
                event = window.event; //针对ie浏览器
                target = event.srcElement;
                code = event.keyCode;
                if (code == 13) {
                    tag = target.tagName;
                    if (tag == "TEXTAREA") { return true; }
                    else { return false; }
                }
            }
            else {
                target = event.target; //针对遵循w3c标准的浏览器，如Firefox
                code = event.keyCode;
                if (code == 13) {
                    tag = target.tagName;
                    if (tag == "INPUT") { return false; }
                    else { return true; }
                }
            }
        };
        
        //------- Start 判断输入的是否是证书和小数还有0
        
        
        function WupperCase(obj){//用户只能输入正负数与小数
         var inum=document.getElementById("A1PH_Level08").value;
                 
         if(inum.length==3){inum=4;}else{inum=3;}
                  
	        if(isNaN(obj.value) && !/^-$/.test(obj.value)){
		        obj.value="";
	        }
	        if(!/^[+-]?\d*\.{0,1}\d{0,1}$/.test(obj.value)){
		        obj.value=obj.value.replace(/\.\d{1,}$/,obj.value.substr(obj.value.indexOf('.'),inum));
	        }
        }
        
        //------- End 判断输入的是否是证书和小数还有0
        

        function Button2_onclick()
        {
 	        var mymessage = confirm("你确定需要保存吗？或者在检查一遍？");
 	                 
 	         
 	        
 	        if(mymessage==true)
 	        {
 	            return true;        
 	             
 	        
 	        }
 	        else
 	        {
 	            return false;
 	        }
 	        	
        }      

        function ResoultFloat(arg1,arg2){
            var t1=0,t2=0,r1,r2;
            try{t1=arg1.toString().split(".")[1].length}catch(e){}
            try{t2=arg2.toString().split(".")[1].length}catch(e){}
            with(Math){
                r1=Number(arg1.toString().replace(".",""));
                r2=Number(arg2.toString().replace(".",""));
                return (r1/r2)*pow(10,t2-t1);
            }
        }
        
        function _SetDigitalInput(oInput)
        {
                var inum=document.getElementById("A1PH_Level08").value;
                
                if(inum.length==3){inum=3;}else{inum=2;}
                
                var f_1 = parseFloat(document.getElementById("B2").value);
                var f_2 = parseFloat(document.getElementById("B3").value);
                var f_3=  parseFloat(document.getElementById("B4").value);
                var f_4=  parseFloat(document.getElementById("B5").value);
                var f_5=  parseFloat(document.getElementById("B6").value);
                var f_6=  parseFloat(document.getElementById("B7").value);
                
                var f_s=f_1+f_2+f_3+f_4+f_5+f_6;
                var Avg_x =ResoultFloat(f_s*10000,6)/10000;
                
                
                var J_1 =  (f_1-Avg_x)*(f_1-Avg_x);
                var J_2 =  (f_2-Avg_x)*(f_2-Avg_x);
                var J_3 = (f_3-Avg_x)*(f_3-Avg_x);
                var J_4 = (f_4-Avg_x)*(f_4-Avg_x);
                var J_5 = (f_5-Avg_x)*(f_5-Avg_x);
                var J_6 = (f_6-Avg_x)*(f_6-Avg_x);
                
                var s_7 = (J_1+J_2+J_3+J_4+J_5+J_6)/5;
                
                var f_f = Math.pow(parseFloat(s_7),0.5);
                
                
                
                document.getElementById("B8").value = changeTwoDecimal_y(Avg_x,inum);   
                document.getElementById("B9").value = changeTwoDecimal_y(f_f,inum); 
                var f_d =100*parseFloat(document.getElementById("B9").value)/parseFloat(document.getElementById("B1").value);
                // alert(f_d);
                document.getElementById("B10").value =changeTwoDecimal_y(f_d,inum);
            
        }
            
        function SetDigitalInputC(oInput)
        {
                var inum=document.getElementById("A1PH_Level08").value;
                
                if(inum.length==3){inum=3;}else{inum=2;}
                
                
                var f=oInput-2;
                var j=oInput-1;
                var i=oInput+1;
                var k=oInput+2;
                
                var f_01 = document.getElementById("C"+oInput).value - document.getElementById("C"+j).value;
                document.getElementById("C"+i).value = changeTwoDecimal_y(f_01,inum);
                var f_02=  document.getElementById("C"+i).value/document.getElementById("C"+f).value*100                 
                document.getElementById("C"+k).value = changeTwoDecimal_y(f_02,inum);                
                                
                // 新增功能：计算C_max的值
                updateValue([4, 9, 14, 19, 24, 29, 34, 39, 44, 49, 54, 59, 64, 69, 74], "C", "C_max");
            
        }

        function SetDigitalInputD(oInput)
        {
                var inum=document.getElementById("A1PH_Level08").value;
                
                if(inum.length==3){inum=3;}else{inum=2;}
                
                var f=oInput-2;
                var j=oInput-1;
                var i=oInput+1;
                var m=oInput+2;
                
                var f_01 = document.getElementById("D"+oInput).value/document.getElementById("D"+f).value;
                document.getElementById("D"+i).value = changeTwoDecimal_y(f_01,inum);
                var f_02 = document.getElementById("D"+i).value - document.getElementById("D"+j).value;
                document.getElementById("D"+m).value = changeTwoDecimal_y(f_02,inum); 

                // 新增功能：计算D_max的值
                updateValue([4, 9], "D", "D_max");
        }
        
        function SetDigitalInputE(oInput)
        {
                var inum=document.getElementById("A1PH_Level08").value;
                
                if(inum.length==3){inum=3;}else{inum=2;}
                
                var f=oInput-3;
                var j=oInput-2;
                var i=oInput-1;
                var k=oInput+1;
                var m=oInput+2;
                
                var f_01 = 100*(document.getElementById("E"+f).value - document.getElementById("E"+oInput).value)/(document.getElementById("E"+oInput).value*(document.getElementById("E"+i).value-25));
                document.getElementById("E"+k).value = changeTwoDecimal_y(f_01,inum);
                var f_02 = (document.getElementById("E"+k).value-2);
                document.getElementById("E"+m).value = changeTwoDecimal_y(f_02,inum);   
                
                // 新增功能：计算E_max的值
                updateValue([5, 11], "E", "E_max");
    
        }

        function SetDigitalInputF(oInput)
        {
                var inum=document.getElementById("A1PH_Level08").value;
                
                if(inum.length==3){inum=3;}else{inum=2;}
                
                var f=oInput-2;
                var j=oInput-1;
                var i=oInput+1;
                var k=oInput+2;
                var f_01 = document.getElementById("F"+oInput).value - document.getElementById("F"+j).value;
                
                document.getElementById("F"+i).value = changeTwoDecimal_y(f_01,inum);
                
                
                if(oInput==12)
                {
                    var f_1 = parseFloat(document.getElementById("F3").value);
                    var f_2 = parseFloat(document.getElementById("F8").value);
                    var f_3 = parseFloat(document.getElementById("F13").value);
                    
                    
                    var f_s=f_1+f_2+f_3;
                    var iAvg =ResoultFloat(f_s*10000,3)/10000;
                
                    
                    
                    document.getElementById("F4").value=document.getElementById("F9").value=document.getElementById("F14").value
                    =changeTwoDecimal_y(iAvg,inum);
                }                
            
        }
        
        function SetDigitalInputBB(oInput)
        {
            
            var inum=document.getElementById("A1PH_Level08").value;
                
            if(inum.length==3){inum=3;}else{inum=2;}
            
            var f=oInput-4;
            var j=oInput-3;
            var i=oInput-2;
            var k=oInput-1;
            
            var m=oInput+4;
            var n=oInput+3;
            var c=oInput+2;
            var d=oInput+1;
            
            var f_1 = parseFloat(document.getElementById("B"+oInput).value);
            var f_2 = parseFloat(document.getElementById("B"+k).value);
            var f_3 = parseFloat(document.getElementById("B"+i).value);
            //var iAvg = (f_1+f_2+f_3)/3;
            var f_s=f_1+f_2+f_3;
            var iAvg =ResoultFloat(f_s*10000,3)/10000;
                    
            document.getElementById("B"+d).value=changeTwoDecimal_y(iAvg,inum);
            
                if(oInput==15)
                {
                document.getElementById("B"+m).value="/";
                    var s_01 = document.getElementById("B"+j).value/document.getElementById("B"+d).value;
                document.getElementById("B"+c).value = changeTwoDecimal_y(s_01,inum);
                
                }
                if(oInput==24)
                {
                document.getElementById("B"+m).value="/";
                var s_02 = document.getElementById("B"+j).value/document.getElementById("B"+d).value;
                document.getElementById("B"+c).value =  changeTwoDecimal_y(s_02,inum);
                var f_01 = parseFloat(document.getElementById("B17").value);
                var f_02 = parseFloat(document.getElementById("B26").value);
                //var f_avg = (f_01+f_02)/2 
                
                var f_s=f_01+f_02;
                var f_avg =ResoultFloat(f_s*10000,2)/10000;
            
                document.getElementById("B18").value= document.getElementById("B27").value
                =changeTwoDecimal_y(f_avg,inum);
                
                }
                if(oInput==33 || oInput==42)
                {
                document.getElementById("B"+c).value="/";
                document.getElementById("B"+n).value="/";
                
                
                var s_f = (document.getElementById("B"+d).value-document.getElementById("B"+j).value)*100/(document.getElementById("B"+f).value);
                document.getElementById("B"+m).value=changeTwoDecimal_y(s_f,inum);
                }
            
        
        
        }
            
        function SetDigitalInputH(oInput)
        {
                
            var inum=document.getElementById("A1PH_Level08").value;
                
            if(inum.length==3){inum=3;}else{inum=2;}
                
                var H_1 = parseFloat(document.getElementById("H2").value);
                var H_2 = parseFloat(document.getElementById("H3").value);
                var H_3 = parseFloat(document.getElementById("H4").value);
                var H_4 = parseFloat(document.getElementById("H5").value);
                var H_5 = parseFloat(document.getElementById("H6").value);
                var H_6 = parseFloat(document.getElementById("H7").value);
                
                if(isNaN(document.getElementById("H2").value) || isNaN(document.getElementById("H3").value)
                || isNaN(document.getElementById("H4").value) || isNaN(document.getElementById("H5").value)
                || isNaN(document.getElementById("H6").value) || isNaN(document.getElementById("H7").value))
                {
                alert("请检查你输入的数字，谢谢！");
                document.getElementById("H2").value=document.getElementById("H3").value
                =document.getElementById("H4").value=document.getElementById("H5").value
                =document.getElementById("H6").value=document.getElementById("H7").value
                =document.getElementById("H8").value=document.getElementById("H9").value
                =document.getElementById("H10").value=document.getElementById("H27").value="/";
                }
                else
                {
                
                    var f_s=H_1+H_2+H_3+H_4+H_5+H_6;
                    var Avg_x =ResoultFloat(f_s*10000,6)/10000;
                //var Avg_x = (H_1+H_2+H_3+H_4+H_5+H_6)/6;
                    document.getElementById("H8").value=changeTwoDecimal_y(Avg_x,inum);
                
                
                var J_1 =  (H_1-Avg_x)*(H_1-Avg_x);
                var J_2 =  (H_2-Avg_x)*(H_2-Avg_x);
                var J_3 = (H_3-Avg_x)*(H_3-Avg_x);
                var J_4 = (H_4-Avg_x)*(H_4-Avg_x);
                var J_5 = (H_5-Avg_x)*(H_5-Avg_x);
                var J_6 = (H_6-Avg_x)*(H_6-Avg_x);
                
                var s_7 = (J_1+J_2+J_3+J_4+J_5+J_6)/5;
                
                var f_f = Math.pow(parseFloat(s_7),0.5);
                
                
                    
                document.getElementById("H9").value = changeTwoDecimal_y(f_f,inum);
                
                var x_f= 100*document.getElementById("H9").value/document.getElementById("H1").value
                
                document.getElementById("H10").value = changeTwoDecimal_y(x_f,inum);
                
                }
                
                if(oInput==7)
                {
                document.getElementById("K1").value = "0.42%FS";
                }                       
            
        }
            
        function changeTwoDecimal_f(x)
        {
            var f_x = parseFloat(x);
            if (isNaN(f_x))
            {
                alert('function:changeTwoDecimal->parameter error');
                return false;
            }
            f_x = Math.round(f_x*100)/100;
            var s_x = f_x.toString();
            var pos_decimal = s_x.indexOf('.');
            if (pos_decimal < 0)
            {
                pos_decimal = s_x.length;
                s_x += '.';
            }
            while (s_x.length <= pos_decimal + 3)
            {
                s_x += '0';
            }
            return s_x;
        }
            
        function changeTwoDecimal_y(s_x,inum)
        {  
             s_x = s_x.toFixed(inum + 1);
            if (isNaN(s_x))
            {
                alert('function:changeTwoDecimal->parameter error');
                return false;
            }
            
            s_x=s_x.toString();
            
           
            
            var pdecimal = s_x.indexOf('.');

            if (pdecimal < 0)
            {
                pdecimal = s_x.length;
                s_x += '.';
            }            
               
            while (s_x.length < parseInt(parseInt(pdecimal)+parseInt(inum+3)))
            {
                s_x += '0';
            }
            
            
            
            var inums = inum+s_x.indexOf('.');

            
            var iReturnValue = "";

            if(s_x.length>(parseInt(inums)+3))
            {
                s_x = s_x.substring(0,(parseInt(inums)+3));
            }
            
           
            if(s_x.length==(parseInt(inums)+3))
            {  
                                 
                              
               var s_x_l = parseInt(s_x.substring(s_x.length-1,s_x.length));
               var s_x_S = parseInt(s_x.substring(s_x.length-2,s_x.length-1));
               var s_x_T = parseInt(s_x.substring(s_x.length-3,s_x.length-2));
               
            
                
                if(s_x_S!=5)
                {
                    return iReturnValue= parseFloat(s_x).toFixed(inum); 

                }
                else if(s_x_S==5 && s_x_l!=0)
                {
                    return iReturnValue= parseFloat(s_x).toFixed(inum);
                    
                }
                else if(s_x_S==5 && s_x_l==0)
                {
                    if(s_x_T%2==0)
                    { 
                        return iReturnValue=parseFloat(s_x.substring(0,parseInt(inums+1))).toFixed(inum);
                         
                    }
                    else
                    {
                         
                         if(inum==1)
                          {
                             
                            var iValue = parseFloat(s_x.substring(0,parseInt(inums+1)));
                            
                            if(parseFloat(s_x)>=0)
                            {
                             
                                 return iReturnValue= parseFloat(iValue+0.1).toFixed(inum);
                            }
                            else
                            {
                            
                                return iReturnValue= parseFloat(iValue-0.1).toFixed(inum);
                            }
                             
                             
                          }
                          else if(inum==2 ||inum==3 )
                          {
                            if(parseFloat(s_x)>=0)
                            {
                               return iReturnValue=parseFloat(parseFloat(s_x.substring(0,parseInt(inums+1)))+parseFloat(inum==2?0.01:0.001)).toFixed(inum);
                            }
                            else
                            {
                            
                                return iReturnValue=parseFloat(parseFloat(s_x.substring(0,parseInt(inums+1)))+parseFloat(inum==2?(-0.01):(-0.001))).toFixed(inum);
                            }
                             
                          }
                          else
                          {
                           
                             return iReturnValue=parseFloat(s_x.substring(0,parseInt(inums+1))).toFixed(inum);
                             

                          }
                    }

                }
               
            }

           

          

        }  
 
        // 新增函数：计算绝对值最大的正值
        function updateValue(fieldIndexes, fieldPrefix, targetFieldId) {
            var values = [];
            
            // 收集所有非空字段的值
            for (var idx = 0; idx < fieldIndexes.length; idx++) {
                var fieldId = fieldPrefix + fieldIndexes[idx];
                var fieldElement = document.getElementById(fieldId);
                
                if (fieldElement && fieldElement.value !== "" && fieldElement.value !== "/") {
                    values.push(parseFloat(fieldElement.value));
                }
            }
            
            // 如果有值，计算绝对值最大的值
            if (values.length > 0) {
                var maxAbsValue = values[0];
                var maxAbs = Math.abs(values[0]);
                
                for (var i = 1; i < values.length; i++) {
                    var absValue = Math.abs(values[i]);
                    // 如果找到更大的绝对值，或者绝对值相等但当前是正值，则更新
                    if (absValue > maxAbs || (absValue === maxAbs && values[i] > 0 && maxAbsValue < 0)) {
                        maxAbsValue = values[i];
                        maxAbs = absValue;
                    }
                }
                
                // 设置目标字段的值
                var targetElement = document.getElementById(targetFieldId);
                if (targetElement) {
                    var inum = document.getElementById("A1PH_Level08").value;
                    var decimalPlaces = (inum.length == 5) ? 3 : 2;
                    targetElement.value = changeTwoDecimal_y(maxAbsValue, decimalPlaces);
                }
            }
        }